$(function() {
	if(getCookieValue("token")==""){
		window.location.href = 'l-userlogin.html'
	}
	getBanner(function(data) {
		$('#center_banner').html(template('center_banner_template', data));
		var gallery = mui('.mui-slider');
		gallery.slider({
			interval: 5000 //自动轮播周期，若为0则不自动播放，默认为0；
		});
	});

	var businessTwo = CD.geturl().business;
	heardLook(function(data) {
		$('#g-usertop').html(template('headerLookTemplate', data));
		var business = data.user.userUuid;
		$('#vipNum').on('tap', function() {
			//window.location.href = "g-center-vip.html?business="+businessTwo;
			//获取codeUrl
			getCodeUrl(function(data) {
				var msgAddress = data.msg;
				console.log(msgAddress);
				//获取支付数据
				var newAddressTo = "redirect_uri=http://www.leyouhui888.cn/card/g-center-vip.html?business="+businessTwo;
				var newAddress = msgAddress.replace("redirect_uri=http%3A%2F%2Fwww.leyouhui888.cn/weChatPay/getAccessToken", newAddressTo)
				window.location = newAddress;
			})

		});
		$('#userUuidCenter').on('tap', function() {
			window.location.href = 'u-home.html?business=' + business + "&login=" + getCookieValue("token");
		});
		$('#myPacketTo').on('tap', function() {
			window.location.href = 'm-mypacket.html?business=' + business
		});

		$('#my_custom').on('tap', function() {
			$('.custom-service').stop().fadeIn()
		});

	});

	//跳转
	function jumpTo(num1, num2) {
		$(num1).on('tap', function() {
			//分享
			var business = CD.geturl.business;
			window.location.href = num2 + '?business=' + newBusiness;
		});
	};

	$('.materialTo').on('tap', function() {
		window.location.href = 'min_page.html?c_user_id=' + businessTwo;
	});
	$('.center-b-card').on('tap', function() {
		window.location.href = 'b-cards.html?business=' + businessTwo;
	});

	$('.myLinksTo').on('tap', function() {
		window.location.href = 'a-link.html?business=' + businessTwo;
	});

	$('.myStoreTo').on('tap', function() {
		window.location.href = 'v-store.html?business=' + businessTwo;
	});

	$('.center-myTo').on('tap', function() {
		window.location.href = 'c-commend.html?business=' + businessTwo;
	});

	$('.center-sign').on('tap', function() {
		window.location.href = 'g-center-signs.html?business=' + businessTwo;
	});
	$('#mirror').on('tap', function() {
		window.location.href = 'g-mirror.html?business=' + businessTwo;
	});

	//客服
	$('.contian-close').on('tap', function() {
		$('.custom-service').stop().fadeOut()
	});

	customer(function(data) {

		$('#list').html(template('listTemplate', data))
	});

})

//个人信息
var heardLook = function(callback) {
	$.ajax({
		type: "post",
		cache: false,
		traditional: true,
		dataType: "json",
		url: window.address + "/user/findBayUserUuid",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		data: {
			"userUuid": CD.geturl().business
		},
		success: function(data) {
			console.log(data);
			callback && callback(data);
		}
	});
}

//电话列表
var customer = function(callback) {
	$.ajax({
		type: "get",
		cache: false,
		traditional: true,
		dataType: "json",
		url: window.address + "/user/listCustomerServicePhoneNo",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		data: "",
		success: function(data) {
			console.log(data);
			callback && callback(data);
		}
	});
}

//获取codeUrl
var getCodeUrl = function(callback) {
	$.ajax({
		type: "get",
		url: window.address + "/weChatPay/getCodeUrl",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		data: '',
		dataType: 'json',
		success: function(data) {
			console.log(data);
			callback && callback(data)
		}
	});
}

//获取轮播
var getBanner = function(callback) {
	$.ajax({
		type: "get",
		url: window.address + "/user/getAd",
		data: '',
		dataType: 'json',
		success: function(data) {
			console.log(data, 888);
			callback && callback(data)
		}
	});
}